﻿using System;
using System.Web.Mvc;

namespace RestUpMVC
{
    public class HandleErrorAttribute : ActionFilterAttribute, IExceptionFilter
    {
        #region Implementation of IExceptionFilter

        public void OnException(ExceptionContext filterContext)
        {
            if (filterContext == null)
            {
                throw new ArgumentNullException("filterContext");
            }
            if (filterContext.IsChildAction)
            {
                return;
            }
            if (filterContext.ExceptionHandled)
            {
                return;
            }

            //var result = HttpResultFactories
            //    .GetFactory(filterContext.RequestContext.HttpContext)
            //    .Create500Result(
            //        new { Message = RestUpMVCResource.HandleErrorAttribute_GenericErrorMessage }
            //    );
            //filterContext.Result = result;
            //filterContext.ExceptionHandled = true;

            // Certain versions of IIS will sometimes use their own error page when
            // they detect a server error. Setting this property indicates that we
            // want it to try to render ASP.NET MVC's error page instead.
            filterContext.HttpContext.Response.TrySkipIisCustomErrors = true;

        }

        #endregion
    }
}